package com.chenchen.tiguan.equipment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chenchen.tiguan.equipment.domain.EquipmentMaintenance;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenchen.tiguan.common.annotation.Log;
import com.chenchen.tiguan.common.core.controller.BaseController;
import com.chenchen.tiguan.common.core.domain.AjaxResult;
import com.chenchen.tiguan.common.enums.BusinessType;
import com.chenchen.tiguan.equipment.service.IEquipmentMaintenanceService;
import com.chenchen.tiguan.common.utils.poi.ExcelUtil;
import com.chenchen.tiguan.common.core.page.TableDataInfo;

/**
 * 设备维修管理Controller
 * 
 * @author chenchen
 * @date 2025-04-13
 */
@RestController
@RequestMapping("/equipment/maintenance")
public class EquipmentMaintenanceController extends BaseController
{
    @Autowired
    private IEquipmentMaintenanceService equipmentMaintenanceService;

    /**
     * 查询设备维修管理列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:maintenance:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentMaintenance equipmentMaintenance)
    {
        startPage();
        List<EquipmentMaintenance> list = equipmentMaintenanceService.selectEquipmentMaintenanceList(equipmentMaintenance);
        return getDataTable(list);
    }

    /**
     * 导出设备维修管理列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:maintenance:export')")
    @Log(title = "设备维修管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentMaintenance equipmentMaintenance)
    {
        List<EquipmentMaintenance> list = equipmentMaintenanceService.selectEquipmentMaintenanceList(equipmentMaintenance);
        ExcelUtil<EquipmentMaintenance> util = new ExcelUtil<EquipmentMaintenance>(EquipmentMaintenance.class);
        util.exportExcel(response, list, "设备维修管理数据");
    }

    /**
     * 获取设备维修管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:maintenance:query')")
    @GetMapping(value = "/{maintenanceId}")
    public AjaxResult getInfo(@PathVariable("maintenanceId") Long maintenanceId)
    {
        return success(equipmentMaintenanceService.selectEquipmentMaintenanceByMaintenanceId(maintenanceId));
    }

    /**
     * 新增设备维修管理
     */
    @PreAuthorize("@ss.hasPermi('equipment:maintenance:add')")
    @Log(title = "设备维修管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentMaintenance equipmentMaintenance)
    {
        return toAjax(equipmentMaintenanceService.insertEquipmentMaintenance(equipmentMaintenance));
    }

    /**
     * 修改设备维修管理
     */
    @PreAuthorize("@ss.hasPermi('equipment:maintenance:edit')")
    @Log(title = "设备维修管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentMaintenance equipmentMaintenance)
    {
        return toAjax(equipmentMaintenanceService.updateEquipmentMaintenance(equipmentMaintenance));
    }

    /**
     * 删除设备维修管理
     */
    @PreAuthorize("@ss.hasPermi('equipment:maintenance:remove')")
    @Log(title = "设备维修管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{maintenanceIds}")
    public AjaxResult remove(@PathVariable Long[] maintenanceIds)
    {
        return toAjax(equipmentMaintenanceService.deleteEquipmentMaintenanceByMaintenanceIds(maintenanceIds));
    }
}
